package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.PurchaseOrder;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.PurchaseOrderService;

public class PurchaseOrderFinaliseProcess extends ProcExec<Integer> {

	private static Logger logger = Logger
			.getLogger(PurchaseOrderCancelProcess.class);
	private PurchaseOrderService purchaseOrderService;

	private String poNumber;
	private String comments;

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		PurchaseOrderFinaliseProcess.logger = logger;
	}

	public PurchaseOrderService getPurchaseOrderService() {
		return purchaseOrderService;
	}

	public void setPurchaseOrderService(
			PurchaseOrderService purchaseOrderService) {
		this.purchaseOrderService = purchaseOrderService;
	}

	public String getPoNumber() {
		return poNumber;
	}

	public void setPoNumber(String poNumber) {
		this.poNumber = poNumber;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	@Override
	public Integer processImpl() {
		PurchaseOrder purchaseOrder = purchaseOrderService
				.getPurchaseOrder(poNumber);
		purchaseOrder.setStatus(ShopGlobalVariables.FINALISED);
		purchaseOrder.setComments(comments);
		try {
			purchaseOrderService.updatePurchaseOrder(purchaseOrder);
		} catch (Exception e) {
			e.printStackTrace();
			setErrorMessage(e.getMessage());
			return ShopGlobalVariables.FAILED;
		}
		return ShopGlobalVariables.SUCCESS;
	}

}
